Bridge pattern is categorized as a structural pattern in GoF because it structurally decouples abstraction from its implementation so that the two can vary independently. However, it is very similar to Strategy pattern which is categorized as a behavioral pattern. source: GoF
0 Comments
Strategy pattern is a behavioral pattern that lets the algorithm vary independently from clients that use it by defining a family of algorithms, encapsulate each one, and make them interchangeable. An algorithm that's encapsulated in this way is called a strategy. Strategy is concerned with changing the behavior of an object. source: GoF The Visitor Pattern is a behavioral design pattern that allows you to define a new operation to be applied to different classes of elements (also known as Visitable classes) without modifying those element classes directly. This pattern groups the same new operation together using a Visitor class, which contains separate member functions for each kind of Element/Visitable class. overviewVisitor pattern lets you add a new operation to a structure of objects (Visitable/Elements) to be traversed through, without changing the Visitable/Element on which it operates. Visitor class separates would-be virtual functions of the Visitable/Element class into a Visitor class. Each Visitable/Element should implement an accept(Visitor) function which delegates the request to the underlying Visitor class via calling visitor.visit(this) from accept(Visitor). Each concrete Visitor class implements a set of visit(Object) functions that does the real work for the operation to be applied to the structure of objects. Each visit(Object) function takes in a different type of concrete Visitable/Element object. The Visitor can optionally maintain a context during a traversal. source: GoF overviewA factory method is a method in a subclass that creates an object. Factory Method pattern defines a Creator interface with Factory Methods (“create” methods) that are implemented by sub-classes. According to Design Patterns by GoF, the intent of Factory Method is to, Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method (pattern) lets a class defer instantiation to subclasses. source: GoF ‘Singleton’ is a fancy word for ‘global variable.’ The intent of Singleton: Ensure a class only has one instance, and provide a global point of access to it. - GOF All singleton implementations offer NO public constructor but only private constructor to enforce non-instantiability. In Java, however, because a private constructor can still be accessed through a backdoor of using reflection, you want to add extra check in the private constructor to guard against reflection vulnerability (see examples below).
overviewWhat is Abstract Factory pattern and what is it for? According to Design Patterns by GoF, the intent of Abstract Factory is to, Provide an interface for creating families of related or dependent objects without specifying their concrete classes. source: GoF overviewWhat is Builder pattern and what is it for? According to Design Patterns by GoF, the intent of Builder is to, Separate the construction of a complex object from its representation so that the same construction process can create different representations. source: GoF |
Categories
All
Archives
May 2020
|